package configuration

import (
	"encoding/json"
	awardM "kop/modules/award/models"
	"kop/modules/configuration/client"
	"kop/pb"
	"kop/util/log"
)

var RankingAwardList []RankingAwardConf

func init() {

	if err := json.Unmarshal(client.Load("IslandRank"), &RankingAwardList); err != nil {
		panic(err)
	}

	log.Info("Load IslandRank.json success.")
}

type RankingAwardConf struct {
	ID            int32 // 索引，无含义
	ActivityID    int32 // 活动ID
	RankMax       int   // 排名最大
	AwardID       int32 // 奖励ID
	LeaderAwardID int32
	MemberAwardID int32
}

func GetLeaderAwards() map[int32]*pb.Award {

	var res = make(map[int32]*pb.Award)

	for _, r := range RankingAwardList {
		res[int32(r.RankMax)] = awardM.RandAward(&pb.Role{}, r.LeaderAwardID)
	}

	return res
}

func GetMemberAwards() map[int32]*pb.Award {

	var res = make(map[int32]*pb.Award)

	for _, r := range RankingAwardList {
		res[int32(r.RankMax)] = awardM.RandAward(&pb.Role{}, r.MemberAwardID)
	}

	return res
}
